package com.creditnet.bmc.platform.config;

import org.apache.shiro.session.Session;
import org.apache.shiro.session.SessionListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * Created by bjmaozhengwei on 2018/3/31.
 */
public class CustomSessionListener implements SessionListener {
    private static final Logger logger = LoggerFactory.getLogger(CustomSessionListener.class);

    private final AtomicInteger sessionCount = new AtomicInteger(0);

    /**
     *  相应会话启动时发生的通知回调
     */
    @Override
    public void onStart(Session session) {
        sessionCount.incrementAndGet();
    }

    /**
     *
     * @param session
     */
    @Override
    public void onStop(Session session) {
        sessionCount.decrementAndGet();
    }

    /**
     * 会话过期时发生的通知回调
     * @param session
     */
    @Override
    public void onExpiration(Session session) {
        sessionCount.decrementAndGet();
    }

    public int getSessionCount(){
        return sessionCount.get();
    }
}
